//
//  LQMainViewController.swift
//  Weibo
//
//  Created by ios on 16/8/8.
//  Copyright © 2016年 ios. All rights reserved.
//

import UIKit

class LQMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
  
        UITabBar.appearance().tintColor = UIColor.orangeColor()
        
        //  设置自定义的Tabbar
        let lqTabBar = LQTabBar()
        lqTabBar.composeButtonClosure = { [weak self] in
            self?.pushComposeVc()
        }
        setValue(lqTabBar, forKey: "tabBar")
        
        //主页
        addChildViewController(LQHomeViewController(), imageName: "tabbar_home", title: "主页")
        //信息
        addChildViewController(LQMessageViewController(), imageName: "tabbar_message_center", title: "信息")
        //发现
         addChildViewController(LQDiscoverViewController(), imageName: "tabbar_discover", title: "发现")
        //我的
         addChildViewController(LQProfileViewController(), imageName: "tabbar_profile", title: "我的")
    }
    
    func addChildViewController(childController: UIViewController, imageName: String, title: String) {
        //  设置图片
        childController.tabBarItem.image = UIImage(named: imageName)
        
        //修改渲染模式，再点击的时候现实原本的颜色
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        //设置文字 ， 设置标题的文字，设置TabBar的文字
        childController.title = title
        //设置文字颜色
        childController.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: .Selected)
        //设置字体大小
       childController.tabBarItem.setTitleTextAttributes([NSFontAttributeName: UIFont.systemFontOfSize(14)], forState: .Normal)
        
        //  添加到导航控制器
        let nav = UINavigationController(rootViewController: childController)
        
        //  给当前对象添加子视图控制器
        
        addChildViewController(nav)
    }
    
    //进入发微博页面
    private func pushComposeVc(){
      let composeVc = LQComposeViewController()
      let nav = UINavigationController(rootViewController: composeVc)
      presentViewController(nav, animated: true, completion: nil)
    }

}
